﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.Modules.Version.AdminSourceSort
{
    public partial class _ajax : JumbotCms.API.AdminCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            ChannelId = Str2Str(q("ccid"));
            id = Str2Str(q("id"));
            Admin_Load("", "json", true);
            this._operType = q("oper");
            switch (this._operType)
            {
                case "ajaxGetList":
                    ajaxGetList();
                    break;
                case "ajaxDel":
                    ajaxDel();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }

        private void DefaultResponse()
        {
            this._response = JsonResult(0, "未知操作");
        }
        private void ajaxGetList()
        {
            //不要指定权限
            doh.Reset();
            doh.SqlCmd = "SELECT [ID],[Title],[ChannelId] FROM [jcms_module_version_source_sort] WHERE [ChannelId]=" + ChannelId + " ORDER BY id";
            DataTable dt = doh.GetDataTable();
            this._response = "{result :\"1\",returnval :\"操作成功\"," + Jumbot.Common.JsonHelp.DtToSON(dt) + "}";
        }
        private void ajaxDel()
        {
            Admin_Load(ChannelId + "-04", "json");
            string cId = f("id");

            doh.Reset();
            doh.SqlCmd = "UPDATE [jcms_module_version_source] SET SortId=0 WHERE [SortId]=" + cId + " and [ChannelId]=" + ChannelId;
            doh.ExecuteSqlNonQuery();

            doh.Reset();
            doh.ConditionExpress = "id=" + cId;
            doh.Delete("jcms_module_version_source_sort");
            this._response = JsonResult(1, "成功删除");
        }
    }
}